function trim(s) {
  while (s.substring(0,1) == ' ') {
    s = s.substring(1,s.length);
  }
  while (s.substring(s.length-1,s.length) == ' ') {
    s = s.substring(0,s.length-1);
  }
  return s;
}

function show_formality_of_cate(){
	var v_count = document.all.tr_root.length;
	for(var i =0; i < v_count; i++){
		if(document.all.tr_root[i].cate_id == document.forms(0).sel_cate(document.forms(0).sel_cate.selectedIndex).id){
			document.all.tr_root[i].style.display = 'block';
		}else{
			document.all.tr_root[i].style.display = 'none';
		}
	}
}
function show_formality_of_agency(){
	var v_count = document.all.tr_root.length;
	for(var i =0; i < v_count; i++){
		if(document.all.tr_root[i].agency_id == document.forms(0).sel_agency(document.forms(0).sel_agency.selectedIndex).id){
			document.all.tr_root[i].style.display = 'block';
		}else{
			document.all.tr_root[i].style.display = 'none';
		}
	}
}
function show_agency_by_cate(){
	var j_cate_id = document.frm_dsp_all_cate_by_agency.sel_cate.value;
	document.frm_dsp_all_cate_by_agency.cate_id.value=j_cate_id;
	var str_fuseaction = 'DISPLAY_ALL_AGENCY_BY_CATE';
	document.frm_dsp_all_cate_by_agency.fuseaction.value=str_fuseaction;
	document.frm_dsp_all_cate_by_agency.submit();
}

function show_page_cate_by_agency_onChange(){
	var j_agency_id = document.frm_agency.sel_author.value;
	//alert(j_agency_id);
	document.frm_agency.agency_id.value=j_agency_id;
	var str_fuseaction = 'DISPLAY_ALL_CATE_BY_AGENCY';
	if (j_agency_id==0){
		str_fuseaction = 'DISPLAY_ALL_AF_BY_ALL_AGENCY';
		}
	document.frm_agency.fuseaction.value=str_fuseaction;
	document.frm_agency.submit();
	 	
}
function set_value(p_from_obj,p_to_obj){
	p_to_obj.value = p_from_obj.value;
}
function show_qa_search_by_time_onClick(p_fuseaction){

	document.frm_qa_search_time.fuseaction.value = p_fuseaction;
	document.frm_qa_search_time.submit();
}

//Ham goi trang ket qua tim kiem nang cao cho AF
function btn_search_af_by_conditions_onclick(){	
	url = "index.php?";
	url = url + "fuseaction=DISPLAY_AF_BY_SEARCH_CONDITIONS";
	url = url + "&method=" + document.f_dsp_all_af.hdn_method.value;
	url = url + "&txt_filter_value=" + document.f_dsp_all_af.txt_filter_value.value;	
	url = url + "&agency_id=" + document.f_dsp_all_af.hdn_back_agency_id.value;
	url = url + "&cate_id=" + document.f_dsp_all_af.hdn_back_cate_id.value;
	window.location = url;
}
// Xu ly khi NSD nhan phim ENTER trong o textbox "Tim Kiem"
function txt_search_af_by_conditions_keydown(){
	var keyCode = (document.layers) ? keyStroke.which : event.keyCode;
	// Phim Enter
	if((keyCode == 13)&& (trim(document.f_dsp_all_af.txt_filter_value.value)!="")){
		btn_search_af_by_conditions_onclick();
		return;
	}	
}
//Ham goi trang ket qua tim kiem nang cao cho QA
function btn_search_qa_by_conditions_onclick(){	
	url = "index.php?";
	url = url + "fuseaction=DISPLAY_ALL_QA_BY_SEARCH_CONDITIONS";
	url = url + "&method=" + document.f_dsp_qa.hdn_method.value;
	url = url + "&txt_filter_value=" + document.f_dsp_qa.txt_filter_value.value;	
	url = url + "&agency_id=" + document.f_dsp_qa.cbo_agency.value;
	url = url + "&cate_id=" + document.f_dsp_qa.cbo_cate.value;
	url = url + "&start_date=" + document.f_dsp_qa.txt_start_date.value;
	url = url + "&end_date=" + document.f_dsp_qa.txt_end_date.value;
	//url = url + "&status=" + document.f_dsp_qa.cbo_status.value;
	//alert(document.f_dsp_qa.txt_end_date.value);
	window.location = url;
}
// Xu ly khi NSD nhan phim ENTER trong o textbox "Tim Kiem"
function txt_search_qa_by_conditions_keydown(){
	var keyCode = (document.layers) ? keyStroke.which : event.keyCode;
	// Phim Enter
	if((keyCode == 13)&& (trim(document.f_dsp_qa.txt_filter_value.value)!="")){
		btn_search_qa_by_conditions_onclick();
		return;
	}	
}
// Xu ly khi NSD nhan phim ENTER trong o textbox "Tim Kiem"
function txt_search_af_by_conditions_keydown(){
	var keyCode = (document.layers) ? keyStroke.which : event.keyCode;
	// Phim Enter
	if((keyCode == 13)&& (trim(document.f_dsp_all_af.txt_filter_value.value)!="")){
		document.f_dsp_all_af.btn_filter.onclick();
		return;
	}	
}
//Ham goi trang ket qua tim kiem theo cum tu cho QA
function btn_search_qa_onclick(f){
	f.hdn_searched_text_qa.value = f.searched_text_qa.value; 
	f.fuseaction.value = "DISPLAY_ALL_QA_BY_FTS";
	f.submit();	
}	
// Xu ly khi NSD nhan phim ENTER trong o textbox "Tim Kiem"
function txt_search_qa_keydown(f){
	var keyCode = (document.layers) ? keyStroke.which : event.keyCode;
	// Phim Enter
	if((keyCode == 13)&& (trim(f.searched_text_qa.value)!="")){
		f.btn_search_qa.onclick();
		return;
	}	
}
//Ham goi trang ket qua tim kiem theo cum tu cho QA
function btn_search_af_onclick(){	
	url = "index.php?";
	url = url + "fuseaction=DISPLAY_ALL_AF_BY_FTS";
	url = url + "&searched_text_af=" + trim(document.f_dsp_fulltext_search.searched_text_af.value);
	window.location = url;
}	
// Xu ly khi NSD nhan phim ENTER trong o textbox "Tim Kiem"
function txt_search_af_keydown(){
	var keyCode = (document.layers) ? keyStroke.which : event.keyCode;
	// Phim Enter
	if((keyCode == 13)&& (trim(document.forms(0).searched_text_af.value)!="")){
		document.forms(0).btn_search_af.onclick();
		return;
	}	
}
function page_onclick(p_value){
	document.forms(1).hdn_page.value = p_value;
	document.forms(1).fuseaction.value = 'DISPLAY_ALL_QA_BY_CATE';
	//document.forms(1).cate_id.value = p_value;
	document.forms(1).submit();
	//btn_save_onclick('DISPLAY_ALL_QA_BY_CATE');
}
function cbo_cate_oncchange(){
	document.forms(1).fuseaction.value = 'DISPLAY_ALL_QA_BY_CATE';
	document.frm_dsp_all_qa_by_cate.hdn_cate_id.value = document.frm_dsp_all_qa_by_cate.cbo_cate.value;
	document.frm_dsp_all_qa_by_cate.submit();
}